import { Injectable } from '@angular/core';
import {FrameContext,BindingData,Repository} from '@farris/devkit';
import { MessagerService } from '@farris/ui-messager';
import { BefRepository, ResponseInfo } from '@farris/bef';
import { EMPTY, of } from 'rxjs';
import { tap, switchMap } from 'rxjs/operators';
@Injectable()
export class SbssdzyhzrDetailFrmControllerService {
  constructor(
     private frameContext:FrameContext,
     private messageService: MessagerService,
  ) {}


  /**
   * 检查数量
   * @Param id 单据ID
   * @remarks 
   * @returns 
   * 检查每个单据明细的数量是否满足扣减
   */
  public checkSl(){
    let compentName = 'hzdmx-component';
    let dataGrid = 'dataGrid_hzdmx'
    let dataGridCompent = this.frameContext.appContext.componentManager.get([compentName,dataGrid])

    let data = dataGridCompent.data

    let rowIndex = 0
    let check = data.some((i,index)=>{
       if (i['kcdh']['szdh_sysl'] < i['zcsl']){
         rowIndex = index + 1
         return true;
       }
       return false
    })

    if (check){
      this.messageService.warning(`第${rowIndex}行错误,申请数量不能大于剩余数量!`);
      return EMPTY;
    }
  }
}
